import 'dart:io';

import 'package:bitcoin_mine/api/api.dart';
import 'package:bitcoin_mine/common/global.dart';
import 'package:bitcoin_mine/http/http_request.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';

class MainController extends GetxController {
  // 当前选中的底部导航索引
  final RxInt currentIndex = 0.obs;

  // 切换底部导航
  void changeBottomNav(int index) {
    if (index != currentIndex.value) {
      currentIndex.value = index;
    }
  }

  void active() async {
    await HttpRequest.instance.requestNetwork<void>(
      Api.active,
      method: "POST",
      params: {
        "platform": Platform.isAndroid ? "1" : "0",
        "device_no": Global.deviceNo ?? "",
        "bundle_id": Global.bundleId ?? "",
        "refer": Global.platformRefer,
      },
      onSuccess: (ignore) {
        if (kDebugMode) {
          print('激活成功');
        }
      },
      onError: (error, stackTrace) {
        if (kDebugMode) {
          print('激活失败: $error');
          print('错误堆栈: $stackTrace');
        }
      },
    );
  }

  // 获取当前页面索引
  int get currentPageIndex => currentIndex.value;
}
